

# Please install OpenAI SDK first: `pip3 install openai`


from DeepSeekAPI import *
import time,json
from config import *
import pandas as pd


t0 = time.time()

# 调用测试
t = TestAPI(api_key, base_url)


# r"E:\项目文件\DeepSeek研究\测试对比文案挑选数据\res_result.xlsx"
# r"C:\Users\Administrator\Desktop\测试---DeepSeek文案\select_line_product_res_result.xlsx"  2025-02-14 17:20:21

desc_path = "/mnt/c/Users/Administrator/Desktop/测试---DeepSeek文案/select_line_product_res_result.xlsx"
df = pd.read_excel(desc_path).head(10)



def get_sku_info(sku):
	
	df_x = df[df['sku']==sku]

	sku = df_x.values[0][0]
	title = df_x.values[0][1]
	five1 = df_x.values[0][3]
	five2 = df_x.values[0][4]
	five3 = df_x.values[0][5]
	five4 = df_x.values[0][6]
	five5 = df_x.values[0][7]
	keywords = df_x.values[0][8]
	info_product = df_x.values[0][9]


	ask_text = f'''You are an Amazon operator with [5] years of experience.
	Step1:
	Use the following [
	'title:{title}',
	'keywords:{keywords}',
	'Features:{info_product}',
	'Spec'
	]
	information to write an Amazon [US] site product copywriting. The product copywriting should output the title, five points and search keywords in [English].
	The number of characters in the title is between [180] and [200]. The title is extracted according to the description information in the following format [precise main keyword + adjective words which describe this product
	+ main function + for + applicable scene/suit for crowd/people +material/color/size/quantity] and does not contain [,] [-] and [precise main keyword ] should contain[ 3 ]to [4 ]units words and 
	behind for should be with [1] to [2] units [Applicable scene]
	The search keyword should output [8] units, and the number of characters of each search keyword should be between [50] and [60] and should not include 'for'
	The five-point description must be five characteristic descriptions, and the number of characters for each description must be between [180] and [300]
	answer only need title 、features 、search keywords ,finally delete the character ','' and '-' of the answer in title and search keywords

	step2:
	Please optimize the title according to the following requirements:
	1.The title is extracted according to the description information in the following format [precise main keyword + adjective words which describe this product
	+ main function + for + applicable scene/suit for crowd/people +material/color/size/quantity]
	2.The title should should contain[ 3 ]to [4] [precise main keyword ] units words 
	3.Behind the title should be with [1] to [2] units [Applicable scene]
	4.Delete ',' and '-' from title 
	5.Title's characters is between [180] and [200] as well keep the content rich for customers to read. 

	Please optimize the search keywors according to the following requirements:
	1. The search keyword should output [10] units
	2. Each search keyword should contain [2]~[3] words and should not include 'for'
	3.The characters of these[10] search keywords's length should be less than [250]

	Please optimize my five points according to the following requirements:
	{{
		'point1': '{five1}',
		'point2':'{five2}',
		'point3':'{five3}',
		'point4':'{five4}',
		'point5':'{five5}'
	}}

	1.The language of the result should be [English]
	2. Reorganize the original content, and the reorganized five points need to highlight the selling points of the product.
	3. Five points are highly readable. Descriptive language should be vivid to attract customers.
	4. There needs to be a subtitle in front of each point as a summary. The content of the subheading needs to be in all caps and enclosed in square brackets.
	5. The ordering of the five-point descriptions should follow the principle of focus on the front, so that users can quickly understand the product situation.
	6. The total number of characters in the five points should be balanced and coordinated, and should not vary too much. lead to poor customer perception.
	7.The expression of the sentence should be complete, and the connection between the sentences should be natural and conform to the reading habit.
	8. Meet the requirements of the Amazon platform for the five points.
	9.Keep the number of characters for each description is [180] and [300] as well the content is rich
	10.Please Sure the length of the optimized five points is more than my five points this is very important
	Please output the optimized five points.
	finally give me the answer by format {{'optimized search keywords':[], 'optimized five points':[]}}
	Note the length of the optimized five points should be more than my five points.

	'''

	messages= [
    {"role": "system", "content": "你是一位资深的Amazon美国站销售经理;有着丰富的产品撰写刊登以及营销能力;只用给你一些产品的基本信息；你就可以将信息打磨成高质量的产品标题用于Amazon刊登"},
    {"role": "user", "content": ask_text}
	]
	#调用测试--test_api1 输入提问语句
	try:
		res = ask_text
		# print(messages)
		# res = t.test_api1(messages=messages) # 测试直接聊天
	except:
		res = "Sorry, I cannot understand your question."

	return sku,title, info_product,res
      



from sqlalchemy import create_engine




for sku in set(df['sku']):
	print(sku)
	sku,title, info_product,res= get_sku_info(sku)
	df_res = pd.DataFrame({'sku':[sku], 'erp_title':[title], 'erp_desc':[info_product], 'DeepSeek_title':[res],'write_time':[time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())]})
	df_res.to_sql('deep_seek_ai_res_tes', con25, if_exists='append', index=False)




# """
# 参考官方文档网址：https://api-docs.deepseek.com/zh-cn/prompt-library/
# ** system: 提示词 给一个定义告诉他是谁 要干啥 指定一个方向
# ** user: 开始提问，输入你的问题以及想到得到的答案要求
# """




# messages= [
#     {"role": "system", "content": "你是一名优秀的数学家"},
#     {"role": "user", "content": "鸡兔共有头50个，腿180个，求鸡和兔的数量？"}
    
# ]



t1 = time.time()
print("Time used:", t1-t0)